package state;

import state.component.Event;
import state.component.EventListener;
import state.util.Hashtable;

public class GameForm extends Sprite implements AlertListener, KeyListener, EventListener {
  private GameImage screen = null;
  private TimerListener timerListener1 = null;
  public boolean isRunning = false;

  protected GroupForm parentGroup = null;

  protected GameForm() {
    super(null, null, 0, 0, GameConstants.TOP_LEFT_ANCHOR);
    _manager = new Manager(this);
    setPosition(0, 0);
    setSize(GameConstants.SCREEN_WIDTH, GameConstants.SCREEN_HEIGHT);
  }

  public final GameImage getScreen() {
    return screen;
  }

  public void setParentGroup(GroupForm parentGroup1) {
    this.parentGroup = parentGroup1;
  }

  public GroupForm getParentGroup() {
    return parentGroup;
  }

  public final void setScreen(GameImage screen1) {
    this.screen = screen1;
  }

  public final Sprite setTimerListener(TimerListener timerListener) {
    if (this.timerListener1 != null) {
      GameGlobal.systemCanvas.getTimer().removeTarget(this.timerListener1);
      this.timerListener1 = null;
    }
    GameGlobal.systemCanvas.getTimer().addTarget(timerListener);
    this.timerListener1 = timerListener;
    return this;
  }

  public final Sprite removeTimerListener() {
    if (timerListener1 != null) {
      GameGlobal.systemCanvas.getTimer().removeTarget(timerListener1);
      timerListener1 = null;
    }
    return this;
  }

  public Sprite setPosition(int x, int y) {
    super.setPosition(x, y);
    _manager.getBaseSprite().setPosition(x, y);
    return this;
  }

  public Sprite setSize(int width, int height) {
    super.setSize(width, height);
    _manager.getBaseSprite().setSize(width, height);
    return this;
  }

  public final void removeScreen() {
    screen = null;
  }

  public void init(Hashtable parameters) {
  }

  public void alertEventPerform(int alertType, int eventType, int alertId) {
  }

  public void draw(Graphics g) {
  }

  public void keyPressed(int keyCode) {
  }

  public void keyReleased(int keyCode) {
  }

  public void keyRepeated(int keyCode) {
  }

  public void mousePressed(int x1, int y1) {
  }

  public void mouseReleased(int x1, int y1) {
  }

  public void mouseMoved(int x1, int y1) {
  }

  public void onPointerDragged(int x1, int y1) {
  }

  public void onPointerPressed(int x1, int y1) {
  }

  public void onPointerReleased(int x1, int y1) {
  }

  public void destroy() {
  }

  public final void doKeyPressed(int keyCode) {
    boolean isMenuShowing = (_manager.getBottomBar() != null) && _manager.getBottomBar().isMenuShowing();
    _manager.doKeyPressed(keyCode);
    if (!isMenuShowing) {
      keyPressed(keyCode);
    }
  }

  public final void doKeyReleased(int keyCode) {
    boolean isMenuShowing = (_manager.getBottomBar() != null) && _manager.getBottomBar().isMenuShowing();
    _manager.doKeyReleased(keyCode);
    if (!isMenuShowing) {
      keyReleased(keyCode);
    }
  }

  public final void doKeyRepeated(int keyCode) {
    boolean isMenuShowing = (_manager.getBottomBar() != null) && _manager.getBottomBar().isMenuShowing();
    _manager.doKeyRepeated(keyCode);
    if (!isMenuShowing) {
      keyRepeated(keyCode);
    }
  }

  public final void doMousePressed(int x1, int y1) {
    _manager.doMousePressed(x1, y1);
    mousePressed(x1, y1);
  }

  public final void doMouseReleased(int x1, int y1) {
    _manager.doMouseReleased(x1, y1);
    mouseReleased(x1, y1);
  }

  public final void doMouseMoved(int x1, int y1) {
    _manager.doMouseMoved(x1, y1);
    mouseMoved(x1, y1);
  }

  public final void doPointerDragged(int x1, int y1) {
    _manager.doPointerDragged(x1, y1);
    onPointerDragged(x1, y1);
  }

  public final void doPointerPressed(int x1, int y1) {
    _manager.doPointerPressed(x1, y1);
    onPointerPressed(x1, y1);
  }

  public final void doPointerReleased(int x1, int y1) {
    _manager.doPointerReleased(x1, y1);
    onPointerReleased(x1, y1);
  }

  public final void updateFullScreen() {
    _manager.updateFullScreen();
  }

  public final void detroyAll() {
    removeScreen();
    isRunning = false;
    removeTimerListener();
    destroy();
    _manager.detroyAll();
  }

  public void onActionPerform(Event event1) {
  }
}
